home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT8 / PG0803.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-05-10  |  9.5 KB  |  206 lines

  1. ***********************************************************************
  2. ;
  3. ;  Program PG0803 ( Chapter 8 )
  4. ;
  5. ;  Drawing colored net in graphics mode
  6. ;
  7. ;  Author: A.I.Sopin, VSU, Voronezh, 1992
  8. ;
  9. ;  BIOS video service is used (functiuon 0Ch of interrupt 10h)
  10. ;
  11. ;  The low-level technique of programming adapter is used
  12. ;
  13. ;  The horizontal line is output pixel by pixel
  14. ;
  15. ;***********************************************************************
  16. .model  small
  17. EXTRN   VIDTYP : FAR
  18. .stack
  19. .data
  20. ;----------------------------------------------------------
  21. N       DW      0       ;  horizontal knots (0, 1 - 64)
  22. M       DW      0       ;  vertical knots (0, 1 - 40)
  23. X       DW      0       ;  horizontal coordinate of pixel (0 - 639)
  24. Y       DW      0       ;  vertical coordinate of pixel (0 - 339)
  25. H_Leng  DW      640     ;  number of points in horisontal direction
  26. V_Leng  DW      400     ;  number of points in vertical direction
  27. Nstr    DW      0       ;  number of lines for output (1 --- 340)
  28. V_Count DW      0       ;  vertical pixel counter (1 --- 18)
  29. Col     DB      0       ;  color (0 --- 15)
  30. VMODE   DB      0       ;  original video mode
  31. TEXT0   DB      ' Demo program for working in graphics mode  (LOW LEVEL).'
  32.     DB      13,10
  33.     DB      ' Press any key for change color or ESC to exit.', 7, '$'
  34. TEXT1   DB      13, 10
  35.     DB      ' EGA or VGA  card not installed !  Press any key...', '$'
  36. ;----------------------------------------------------------
  37. .code
  38. .startup
  39.     mov     ah,0Fh                  ;  function 0Fh - get video mode
  40.     int     10h                     ;  BIOS video service call
  41.     mov     VMODE,al                ;  save original video mode
  42.     mov     ah,00                   ;  function 00h - set video mode
  43.     mov     al,03h                  ;  mode 3 (80x25  color)
  44.     int     10h                     ;  BIOS video service call
  45.     mov     ah,2                    ;  function 02h - set cursor
  46.     mov     dx,0                    ;  initial cursor position - 0, 0
  47.     mov     bh,0                    ;  video page 0
  48.     int     10h                     ;  BIOS video service call
  49. ;  Check whether EGA or VGA installed
  50.     Call    VIDTYP                  ;  determine cideo adapter type
  51.     cmp     al,3                    ;  EGA  or  VGA ?
  52.     jnl     Graph                   ;  OK
  53.     lea     dx,TEXT1                ;  address of string for output
  54.     mov     ah,9                    ;  function 09h - output string
  55.     int     21h                     ;  DOS service call
  56.     mov     ah,0                    ;  function 00h - get key
  57.     int     16h                     ;  BIOS keyboard service call
  58.     jmp     short Exit              ;  to finishing program
  59. ;  Output initial message and set graphics mode
  60. Graph:  lea     dx,TEXT0                ;  address of string for output
  61.     mov     ah,9                    ;  function 09h - output string
  62.     int     21h                     ;  DOS service call
  63.     xor     ah,ah                   ;  function 00h - get key
  64.     int     16h                     ;  BIOS keyboard service call
  65.     mov     ah,0                    ;  function 00h - set video mode
  66.     mov     al,10h                  ;  Color  640x350
  67.     int     10h                     ;  BIOS video service call
  68. ;  Setting the writing mode required
  69.     mov     dx,3CEh                 ;  address register
  70.     mov     al,5                    ;  index for register 5
  71.     out     dx,al                   ;  send index
  72.     inc     dx                      ;  3CFh - mode register
  73.     xor     al,al                   ;  writing mode 0
  74.     out     dx,al                   ;  send writing mode
  75.     mov     Col,0                   ;  initial color (black)
  76. ;-------------------------------------------------------------------
  77. ;  Output colored net into the screen
  78. Loop0:  mov     Nstr,0                  ;  upper line number
  79. Loop1:  Call    HORLINE                 ;  draw horizontal line
  80.     Call    VLINES                  ;  output vertical lines
  81.     add     Nstr,20                 ;  Next Line
  82.     cmp     Nstr,340                ;  Last Line ?
  83.     jl      Loop1                   ;
  84. ;  Change color when a key has been pressed
  85.     xor     ah,ah                   ;  function 00h - get key
  86.     int     16h                     ;  BIOS keyboard service call
  87.     cmp     al,1Bh                  ;  Esc ?
  88.     je      Exit                    ;  yes, finish program
  89.     inc     Col                     ;  change color code
  90.     cmp     Col,15                  ;  all colors shown?
  91.     jng     Loop0                   ;  no, show next color
  92.     mov     Col,0                   ;  set initial color (black)
  93.     jmp     short Loop0             ;  continue
  94. ;-------------------------------------------------------------------
  95. ;  Finish program and return to MS-DOS
  96. Exit:   mov     ah,0                    ;  function 0 - set video mode
  97.     mov     al,VMODE                ;  AL - original mode
  98.     int     10h                     ;  BIOS video service call
  99.     mov     ax,4C00h                ;  Function 4Ch - terminate process
  100.     int     21h                     ;  DOS service call
  101. ;-------------------------------------------------------------------
  102. ;
  103. ;  Output pixel onto screen
  104. ;
  105. ;  AL  - color of pixel
  106. ;
  107. ;  CX  - horizontal coordinate  (column) X = (0 --- 640)
  108. ;
  109. ;  DX  - vertical coordinate (row)    Y = (0 --- 340)
  110. ;
  111. ;  ES  - base address of videobuffer ( 0A000h  for 16 colors 640x350)
  112. ;
  113. ;  Registers  AX, BX, SI, DI  are overwritten!
  114. ;
  115. ;-------------------------------------------------------------------
  116. WR_DOT  PROC   NEAR
  117.     mov     si,cx                   ;  horizontal coordinate
  118.     mov     di,dx                   ;  vertical coordinate
  119.     push    ax                      ;  save color
  120.     mov     ax,0A000h               ;  base address of videobuffer
  121.     mov     es,ax                   ;  ES points to videobuffer
  122. ;  determining the mask for output the bit required
  123.     and     cx,0007h                ;  remainder after dividing by 8
  124.     mov     ah,80h                  ;  mask for 7th bit
  125.     shr     ah,cl                   ;  mask
  126.     mov     dx,3CEh                 ;  address of video register
  127.     mov     al,8                    ;  register's number
  128.     out     dx,ax                   ;  write mode and mask
  129. ;  determining the address of byte in graphics buffer
  130.     mov     bx,si                   ;  X - horizontal coordinate
  131.     shr     bx,1                    ;  /2
  132.     shr     bx,1                    ;  /4
  133.     shr     bx,1                    ;  /8 - offset from start of line
  134.     mov     ax,di                   ;  Y - vertical coordinate
  135.     xor     dx,dx                   ;  clear high part
  136.     mov     cx,80                   ;  multiplier
  137.     mul     cx                      ;
  138.     add     bx,ax                   ;  BX - address of pixel in line
  139.     mov     al,es:[bx]              ;  read latch value
  140. ;  set register of mask for color required
  141.     mov     dx,3C4h                 ;  address register
  142.     mov     ax,0F02h                ;  index of mask register
  143.     out     dx,ax                   ;  set address
  144.     mov     byte ptr es:[bx],0      ;  clear latch
  145.     inc     dx                      ;  3C5h - data register
  146.     pop     ax                      ;  restore color
  147.     out     dx,al                   ;  send color code
  148.     mov     byte ptr es:[bx],0FFh   ;  output pixel ES:[BX]
  149.     mov     cx,si                   ;  horizontal coordinate
  150.     mov     dx,di                   ;  vertical coordinate
  151.     RETN
  152. WR_DOT  ENDP
  153. ;-------------------------------------------------------------------
  154. ;
  155. ;  Output horizontal line pixel by pixel
  156. ;
  157. ;-------------------------------------------------------------------
  158. HORLINE PROC   NEAR
  159.     xor     cx,cx                   ;  X - initial column for output
  160. HOR1:   mov     dx,Nstr                 ;  Y - row for output
  161.     mov     al,Col                  ;  color of pixel
  162.     Call    WR_DOT                  ;  output one pixel
  163.     inc     cx                      ;  number of next pixel
  164.     cmp     cx,H_Leng               ;  end of line?
  165.     jl      HOR1                    ;  no, continue output
  166.     RETN                            ;  return to caller
  167. HORLINE ENDP
  168. ;-------------------------------------------------------------------
  169. ;
  170. ;  Drawing vertical lines from knots
  171. ;
  172. ;  Is performed after a horizontal line has been output
  173. ;
  174. ;  CX - horizontal pixel coordinate (row)
  175. ;
  176. ;  DX - vertical pixel coordinate (column)
  177. ;
  178. ;-------------------------------------------------------------------
  179. VLINES  PROC   NEAR
  180.     cmp     Nstr,340                ;  Last Line ?
  181.     je      VLIN5                   ;  yes, return
  182.     cmp     Nstr,0                  ;  first line ?
  183.     jz      VLIN5                   ;  yes, return
  184.     xor     cx,cx                   ;  initial column = 0
  185. VLIN2:  mov     V_Count,20              ;  length of vertical line
  186.     mov     dx,Nstr                 ;  initial row
  187.     sub     dx,19                   ;  number of pixel
  188. ;  Output vertical line from upper line to current line
  189. VLIN3:  mov     al,Col                  ;  pixel color
  190.     Call    WR_DOT                  ;  output pixel
  191.     inc     dx                      ;  address of bottom pixel
  192.     dec     V_Count                 ;
  193.     jg      VLIN3                   ;  continue output
  194. ;  Next knot in horizontal direction
  195.     mov     si,32                   ;  length of string
  196.     and     cx,cx                   ;  begiining of the line?
  197.     jg      VLIN4                   ;  no
  198.     mov     si,31                   ;  to knot 2
  199. VLIN4:  add     cx,si                   ;  next horizontal knot
  200.     cmp     cx,639                  ;  end of line?
  201.     jng     VLIN2                   ;
  202. VLIN5:  RETN                            ;  return
  203. VLINES  ENDP
  204. ;-------------------------------------------------------------------
  205.     END
  206.